//大数据223 范名念 202249020109
#include <stdio.h>

int seq_search(int array[],int n,int k,int seek_seq[]){
    int i;
    for(i=0;i<n;i++){
        if(array[i] == k){
            seek_seq[i] = i;
            return 0;
        } else{
            seek_seq[i] = i;
        }
    }
    return -1;
}

int bin_search(int array[],int n,int k,int seek_seq[]){
    int i,low,mid,high;
    i=0;
    low=0;
    high=n-1;
    if(low>high){
        return -1;
    }
    while (low<=high){
        mid=(low+high)/2;
        if(k<array[mid]){
            high=mid - 1;
            seek_seq[i]=mid;
        } else if(k>array[mid]){
            low = mid + 1;
            seek_seq[i]=mid;
        } else{
            seek_seq[i]=mid;
            return 0;
        }
        i++;
    }
}

int main() {
    int array[10] = {0,1,2,3,4,5,6,7,8,9};
    int seek_seq[10];
    int i,j;
    for (j = 0; j < 10; j++) {
        seek_seq[j]=-1;
    }
    seq_search(array,10,5,seek_seq);
    printf("5 found at index: \n");
    for (i = 0; i < 10; i++) {
        if(seek_seq[i]<0)
            break;
        printf("%d\t",seek_seq[i]);
    }
    for (j = 0; j < 10;j ++) {
         seek_seq[j]=-1;
    }
    bin_search(array,10,2,seek_seq);
    printf("\n2 found at index: ");
    for (i = 0; i <10 ;i ++) {
        if(seek_seq[i]<0)
            break;
        printf("%d\t",seek_seq[i]);
    }
    return 0;
}
